<?php

declare(strict_types=1);

namespace App\Chat\Listener;

use App\Chat\Event\TalkEvent;
use App\Chat\Service\Message\SubscribeHandleService;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use App\Chat\Support\Message;

#[Listener]
class TalkMessageListener implements ListenerInterface
{
    public function listen(): array
    {
        // 返回一个该监听器要监听的事件数组，可以同时监听多个事件
        return [
            TalkEvent::class,
        ];
    }

    /**
     * @param object $event
     */
    public function process(object $event): void
    {
//        Message::publish(Message::create($event->event_name, $event->data));
        $data = Message::create($event->event_name, $event->data);
        di()->get(SubscribeHandleService::class)->handle($data);
    }
}